package com.kkd.kkdapp.adapter;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.kkd.kkdapp.R;
import com.kkd.kkdapp.base.MyBaseAdapter;
import com.kkd.kkdapp.http.entity.RepaymentScheduleData;

public class RepaymentScheduleAdapter extends
		MyBaseAdapter<RepaymentScheduleData> {

	LayoutInflater mInflater;
	private List<RepaymentScheduleData> mList;
	private DecimalFormat df;

	public RepaymentScheduleAdapter(Context context) {
		super(context);
		mInflater = LayoutInflater.from(context);
		mList = this.getAdapterData();
		df = new DecimalFormat("0.00");
	}

	@SuppressLint("SimpleDateFormat")
	@Override
	public View getMyView(int position, View convertView, ViewGroup parent) {
		ViewHodler mViewHodler;
		if (convertView == null) {
			mViewHodler = new ViewHodler();
			convertView = mInflater.inflate(R.layout.repayment_list_item, null);
			mViewHodler.repayTime = (TextView) convertView
					.findViewById(R.id.repay_time);
			mViewHodler.repayCount = (TextView) convertView
					.findViewById(R.id.repay_count);
			mViewHodler.value1 = (TextView) convertView
					.findViewById(R.id.value1);
			mViewHodler.value2 = (TextView) convertView
					.findViewById(R.id.value2);
			mViewHodler.repayment_img = (ImageView) convertView
					.findViewById(R.id.repayment_img);
			convertView.setTag(mViewHodler);

		} else {
			mViewHodler = (ViewHodler) convertView.getTag();
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String ShouldpayDate = sdf.format(new Date(myList.get(position)
				.getShouldpayDate()));
		mViewHodler.repayTime.setTag(position);
		mViewHodler.repayTime.setText(ShouldpayDate);
		mViewHodler.repayCount.setTag(position);
		mViewHodler.repayCount.setText("" + mList.get(position).getBillNum());
		String mTotal = df.format(mList.get(position).getTotal() * 0.01);
		mViewHodler.value1.setTag(position);
		mViewHodler.value1.setText(mTotal);
		mViewHodler.value2.setTag(position);
		String mPaymentMoney = df
				.format(mList.get(position).getPaymentMoney() * 0.01);
		mViewHodler.value2.setText(mPaymentMoney);
		if (201 == mList.get(position).getPaymentStatus()) {
			mViewHodler.repayment_img.setVisibility(View.INVISIBLE);
		} else {
			mViewHodler.repayment_img.setVisibility(View.VISIBLE);
		}
		return convertView;
	}

	class ViewHodler {
		TextView repayTime;
		TextView repayCount;
		TextView value1;
		TextView value2;
		ImageView repayment_img;
	}
}
